package com.wzgl.core.model;


import java.util.LinkedList;
import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.wzgl.core.base.Table;
import com.wzgl.core.baseModel.BaseDicinfo;
import com.wzgl.core.utils.StringUtils;
import com.wzgl.core.vo.LableVo;

/***
 * 数据字典表
 * @author Administrator
 *
 */
@Table(tableName = "tdicinfo", primaryKey = "fid")
public class Tdicinfo extends BaseDicinfo<Tdicinfo> {
	private static final long serialVersionUID = -1L;
	public static final Tdicinfo dao = new Tdicinfo();
	
	public List<Tdicinfo> getAll(){
		return dao.find("select * from Tdicinfo where  ifnull(fstats,0) >=0");
	}
	
//	public List<LableVo> fidAll(){
//		return dao.find("select * from Tdicinfo where  ifnull(fstats,0) >=0");
//	}
	
	public Tdicinfo findById(final String fid) {
		return dao.doFindFirst("fid = ? and ifnull(fstats,0) >=0", fid);
	}
	
	public Tdicinfo findByCode(final String fode) {
		return dao.doFindFirst("fode = ? and ifnull(fstats,0) >=0", fode);
	}
	
	public Tdicinfo findBySort(final String fsortcode) {
		return dao.doFindFirst("fsortcode = ? and ifnull(fstats,0) >=0", fsortcode);
	}
	
	public List<Tdicinfo> getTdicBySort(final String fsortcode){
		return dao.find("select * from Tdicinfo where fsortcode = ? and ifnull(fstats,0) >=0 ORDER BY fdate",fsortcode);
	}
	public Page<Tdicinfo> getListByVal(int page, int pagesize,final String fvalue,final String fsortcode){
		LinkedList<Object> params = new LinkedList<Object>();
		StringBuilder sql = new StringBuilder(" from tdicinfo u left join tdicsort s on s.fsortcode = u.fsortcode where ifnull(u.fstats,0) >=0");
		if (StringUtils.isNotBlank(fsortcode)) {
			sql.append(" AND u.fsortcode =  ? ");
			params.add(fsortcode);
		}
		if (StringUtils.isNotBlank(fvalue)) {
			sql.append(" AND u.fvalue like ? ");
			params.add("%" + fvalue + "%");
		}
		sql.append(" ORDER BY u.fdate,u.fsortcode");
		return dao.paginate(page, pagesize, "select u.*,s.fname fsortname ", sql.toString(), params.toArray());
	}
}
